//
//  JJHomeViewController.m
//  DemoPro
//
//  Created by vpjacob on 2017/4/7.
//  Copyright © 2017年 vpjacob. All rights reserved.
//

#import "JJHomeViewController.h"
#import "JJTestNetApi.h"
#import "JJTestDemoModel.h"

@interface JJHomeViewController ()

@end

@implementation JJHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    [self requestDataWithTest];
    self.title = @"首页";
    [self.jjTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:self.jjTableView];
    self.title = @"我的";
    [self requestNet];
    JJ_WS(weakself);
    [self addMJRefreshHeadView:^(NSInteger page) {
        [weakself requestNet];
    }];
    [self addMJRefreshFootView:^(NSInteger page) {
        [weakself requestNet];
    }];
    
}

- (void)requestNet {
    [super didReceiveMemoryWarning];
    JJTestNetApi* api = [JJTestNetApi new];
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        NSDictionary* dict = request.responseObject[@"videoSidList"];
        self.dataArray = [JJTestDemoModel changeResponseJSONObject:dict];
        
        [self requestSuccess:YES requestEnd:self.dataArray.count < 20];
        [self.jjTableView reloadData];
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.contentView.backgroundColor = [UIColor redColor];
    JJTestDemoModel* model = self.dataArray[indexPath.row];
    cell.textLabel.text = model.imgsrc;
    NSLog(@"%@",model.imgsrc);
    return cell;
}
@end
